package sjtu.rfid.rri.services.ale.report;

import java.net.URI;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import sjtu.rfid.rri.services.ale.reading.ECInitiationCondition;
import sjtu.rfid.rri.services.ale.reading.ECReports;
import sjtu.rfid.rri.services.ale.reading.ECTerminationCondition;
import sjtu.rfid.rri.services.ale.reading.ECTrigger;
import sjtu.rfid.rri.services.ale.writing.CCCmdReport;
import sjtu.rfid.rri.services.ale.writing.CCInitiationCondition;
import sjtu.rfid.rri.services.ale.writing.CCReports;
import sjtu.rfid.rri.services.ale.writing.CCTerminationCondition;
import sjtu.rfid.rri.services.tag.TagEvent;

/**
 * 
 * @author jinghao
 * 
 */
public interface ReportBuildService {

	/**
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param ALEID
	 *            the ALEID
	 * @param spec
	 *            the ALE cycle control spec, e.g. an ECSpec object
	 * @param type
	 *            the ReportBuildType
	 * @throws ReportBuildNotFoundException
	 */
	void submit(String specName, String ALEID, Object spec, ReportBuildType type)
			throws ReportBuildNotFoundException;

	/**
	 * 
	 * @param specName
	 *            the name of the ALE cycle control specF
	 */
	void release(String specName);

	/**
	 * Build ECReports.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param tagEvents
	 * @param totalMilliseconds
	 * @param initCondition
	 * @param termCondition
	 * @param startECTrigger
	 * @param stopECTrigger
	 */
	void buildECReports(String specName, List<TagEvent> tagEvents,
			long totalMilliseconds, ECInitiationCondition initCondition,
			ECTerminationCondition termCondition, ECTrigger startECTrigger,
			ECTrigger stopECTrigger);

	/**
	 * Build CCReports.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param cmdReports
	 * @param totalMilliseconds
	 * @param initCondition
	 * @param termCondition
	 * @param startECTrigger
	 * @param stopECTrigger
	 */
	void buildCCReports(String specName, List<CCCmdReport> cmdReports,
			long totalMilliseconds, CCInitiationCondition initCondition,
			CCTerminationCondition termCondition, ECTrigger startECTrigger,
			ECTrigger stopECTrigger);

	/**
	 * Build ECReports and notify to subscribers.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param tagEvents
	 * @param totalMilliseconds
	 * @param initiationCondition
	 * @param terminationCondition
	 * @param startECTrigger
	 * @param stopECTrigger
	 * @param subscribers
	 */
	void notifyECReports(String specName, List<TagEvent> tagEvents,
			long totalMilliseconds, ECInitiationCondition initiationCondition,
			ECTerminationCondition terminationCondition,
			ECTrigger startECTrigger, ECTrigger stopECTrigger,
			Set<URI> subscribers);

	/**
	 * Build CCReports and notify to subscribers.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param cmdReports
	 * @param totalMilliseconds
	 * @param initiationCondition
	 * @param terminationCondition
	 * @param startECTrigger
	 * @param stopECTrigger
	 * @param subscribers
	 */
	void notifyCCReports(String specName, List<CCCmdReport> cmdReports,
			long totalMilliseconds, CCInitiationCondition initiationCondition,
			CCTerminationCondition terminationCondition,
			ECTrigger startECTrigger, ECTrigger stopECTrigger,
			Set<URI> subscribers);

	/**
	 * Abort the reports building. This will ends with no reports delivered.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 */
	void abortReports(String specName);

	/**
	 * Fetch an ECReports generated by current Active Cycle. <br>
	 * This operation may pending until the Cycle ends or when timeout.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param timeout
	 *            the maximum time to wait in milliseconds. <br>
	 *            Specify a value equal or less than zero to wait forever.
	 * @param unit
	 * @return
	 */
	ECReports fetchECReports(String specName, long timeout, TimeUnit unit);

	/**
	 * Fetch a CCReports generated by current Active Cycle. <br>
	 * This operation may pending until the Cycle ends or when timeout.
	 * 
	 * @param specName
	 *            the name of the ALE cycle control spec
	 * @param timeout
	 *            the maximum time to wait in milliseconds. <br>
	 *            Specify a value equal or less than zero to wait forever.
	 * @param unit
	 * @return
	 */
	CCReports fetchCCReports(String specName, long timeout, TimeUnit unit);

}
